<template>
  <div class="mui-numbox" data-numbox-min="1" :data-numbox-max="nummax">
    <!-- "-"按钮，点击可减小当前数值 -->
    <button class="mui-btn mui-numbox-btn-minus" type="button">-</button>
    <input class="mui-numbox-input" type="number" value="1" @change="countChanged" ref="numbox" />
    <!-- "+"按钮，点击可增大当前数值 -->
    <button class="mui-btn mui-numbox-btn-plus" type="button">+</button>
  </div>
</template>

<script>
import mui from "../../lib/mui/js/mui.js";
export default {
  mounted() {
    mui(".mui-numbox").numbox();
  },
  methods: {
    // 只要 一改变 input 的值就立即把数据传给父组件
    countChanged() {
      this.$emit("getcount", this.$refs.numbox.value);
    }
  },
  props: ["nummax"],
  watch: {
    // 属性监听
    nummax: function(newVal, oldVal) {
      mui(".mui-numbox")
        .numbox()
        .setOption("max", this.nummax);
    }
  }
};
</script>

<style>
</style>